package ro.toporjinschi.anytaxi;

import java.util.List;

import ro.toporjinschi.androidorm.EntityManager;
import ro.toporjinschi.androidorm.Query;
import ro.toporjinschi.anytaxi.database.DatabaseAccess;
import ro.toporjinschi.anytaxi.database.beans.Place;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ProgressBar;

public class Splash extends Activity {
    private ProgressBar progress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        this.progress = (ProgressBar) findViewById(R.id.pbSplash);
        new LoadDatabase(this.progress).execute(this.getBaseContext());
    }

    @Override
    protected void onPause() {
        this.progress.setProgress(100);
        super.onPause();
        super.finish();
    }

    protected class LoadDatabase extends AsyncTask<Context, Integer, String> {
        private DatabaseAccess db;
        private final ProgressBar progressBar;

        public LoadDatabase(ProgressBar progressBar) {
            this.progressBar = progressBar;
        }

        @Override
        protected String doInBackground(Context... params) {
//            EntityManager em = EntityManager.getInstance();
//            em.get(Place.class);
            return null;
        }

        private void waitASec() {
            synchronized (this) {
                try {
                    this.wait(1000);
                } catch (final InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
            this.progressBar.setProgress(values[0]);
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            publishProgress(80);
            startActivity(new Intent("ro.toporjinschi.anytaxi.MAINACTIVITY"));
            publishProgress(90);
        }

        private void readPlaces() {
            this.db.getReadableDatabase();
            this.db.close();
        }
    }
}